"""
Case Type   : 功能测试
Case Name   : cubi函数对于整型数据可以开立方开尽和无法开尽的数据进行运算校验
Create At   : 2020/8/2
Owner       : @li-xin12345
Description : 描述
    步骤 1.查看数据库状态，如果数据库没有启动则执行启动，如果已经启动则无操作
    步骤 2.执行SELECT ||/ {int} AS RESULT;进行开立方并且校验所得结果
Expect      : 
    步骤 1：数据库状态正常
    步骤 2：环境清理成功
History     :
"""
import os
import unittest
import sys

sys.path.append(sys.path[0] + "/../")
from testcase.utils.Common import Common
from testcase.utils.Constant import Constant
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Logger import Logger

logger = Logger()
common = Common()
commonsh = CommonSH('dbuser')

class Cubic_003(unittest.TestCase):

    def setUp(self):
        logger.info(f'-----{os.path.basename(__file__)} start-----')
        self.constant = Constant()
        logger.info("-----------查询数据库状态-----------")
        commonsh.ensure_dbstatus_normal()
        global clear_sql
        clear_sql = 'drop table if exists data_01;'
        SqlMdg1 = commonsh.execut_db_sql(clear_sql)
        logger.info(SqlMdg1)

    def test_cubic_003(self):
        sql = 'create table data_01 (clo1 float,clo2 float);' \
              'insert into data_01 values (1, 124);'
        res = commonsh.execut_db_sql(sql)
        logger.info(res)
        self.assertIn(self.constant.CREATE_TABLE_SUCCESS, res)
        self.assertIn('INSERT 0 1', res)
        sql = 'select  ||/clo1 from data_01;'
        res = commonsh.execut_db_sql(sql)
        logger.info(res)
        self.assertIn('1', res.splitlines()[-2].strip())
        sql = 'select  ||/clo2 from data_01;'
        res = commonsh.execut_db_sql(sql)
        logger.info(res)
        self.assertIn('4.98663095223865', res.splitlines()[-2].strip())
        sql = 'select ||/ 101 as result;'
        res = commonsh.execut_db_sql(sql)
        logger.info(res)
        self.assertIn('4.65700950780384', res.splitlines()[-2].strip())

    def tearDown(self):
        SqlMdg = commonsh.execut_db_sql(clear_sql)
        logger.info(SqlMdg)
        logger.info(f'-----{os.path.basename(__file__)} end-----')